package com.tulink.yichutu.controller.weixin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.tulink.yichutu.common.utils.DataResult;

import com.tulink.yichutu.entity.WxUserEntity;
import com.tulink.yichutu.service.WxUserService;



/**
 * 微信扫码表
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2021-04-04 20:05:02
 */
@Controller
@RequestMapping("/")
public class WxUserController {
    @Autowired
    private WxUserService wxUserService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/wxUser")
    public String wxUser() {
        return "wxuser/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("wxUser/add")
    @RequiresPermissions("wxUser:add")
    @ResponseBody
    public DataResult add(@RequestBody WxUserEntity wxUser){
        wxUserService.save(wxUser);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("wxUser/delete")
    @RequiresPermissions("wxUser:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        wxUserService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("wxUser/update")
    @RequiresPermissions("wxUser:update")
    @ResponseBody
    public DataResult update(@RequestBody WxUserEntity wxUser){
        wxUserService.updateById(wxUser);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("wxUser/listByPage")
    @RequiresPermissions("wxUser:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody WxUserEntity wxUser){
        Page page = new Page(wxUser.getPage(), wxUser.getLimit());
        LambdaQueryWrapper<WxUserEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(WxUserEntity::getId, wxUser.getId());
        IPage<WxUserEntity> iPage = wxUserService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
